<?php
namespace app\common\model;

class AuthGroupRuleModel extends BaseModel
{
    protected $name = 'auth_group_rule'; //定义用户表
    //开启自动写入时间戳
    protected $autoWriteTimestamp = false;
    // 定义自动完成的属性
    protected $auto = []; //新增修改
    protected $insert = []; //插入
    protected $update = []; //修改
    protected $type = [];

    /**
     * 添加权限规则
     */
    public function addRule($groupId,$rule){
        $this->where('group_id',$groupId)->delete(); //先删除对应组规则
        if(empty($rule)) return true;
        $dataList=[];
        foreach($rule as $v){
            if(empty($v['btn'])){
                $ruleBtn='';
            }else{
                $ruleBtn=implode(',',$v['btn']);
            }
            $dataList[]=['group_id'=>$groupId,'rule_id'=>$v['rule_id'],'rule_button'=>$ruleBtn];
        }
        $this->saveAll($dataList);
        return true;
    }
}




